Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pool CancellationTokenSources #1297

Merged
merged 3 commits into from
Oct 20, 2021
Merged

Pool CancellationTokenSources #1297

merged 3 commits into from
Oct 20, 2021

Conversation

MihaZupan
Copy link
Member

Fixes #902
Contributes to #1055

I will post an allocation profile here before merging as well.
It should be the same as #876 (comment) for 6.0 + a few state machine/object size reductions.

load lin-citrine-net60-yarp-http-http-100B lin-citrine-net60-yarp-http-http-100B-local
Requests 14.591.185 14.848.700 +1,76%
Bad responses 0 0
Mean latency (us) 1.050 1.032 -1,74%
Max latency (us) 48.932 39.009 -20,28%
Requests/sec 243.194 247.529 +1,78%
Requests/sec (max) 262.924 267.700 +1,82%

The RPS change across multiple runs seems to be around 1 - 1.5%.

This change relies on #1271 for correctness - a rogue StreamCopier must not be allowed to run when we're exiting SendAsync.

@MihaZupan MihaZupan added this to the YARP RC1 milestone Oct 19, 2021
@MihaZupan MihaZupan requested a review from Tratcher as a code owner October 19, 2021 10:55
@Kahbazi
Copy link
Collaborator

Kahbazi commented Oct 19, 2021

CancellationTokenSource in ActiveHealthCheckMonitor could also be pooled.

var cts = new CancellationTokenSource(timeout);

@MihaZupan
Copy link
Member Author

MihaZupan commented Oct 19, 2021

Looking at the ActiveHealthCheckMonitor logic, I'm seeing an unrelated bug (#1299), so I will look at using a pooled CTS there in a separate PR.

@MihaZupan
Copy link
Member Author

MihaZupan commented Oct 19, 2021

As expected, the allocations for CTS machinery are saved per request (4 objects - 304 bytes).
StreamCopyHttpContent, HttpForwarder.SendAsync and StreamCopier.CopyAsync's state machines are 8 bytes smaller.

System Threading

@karelz karelz removed this from the YARP RC1 milestone Oct 19, 2021
Copy link
Member

@Tratcher Tratcher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm amused we're taking turns modifying the same lines of code.

@MihaZupan MihaZupan added this to the YARP RC1 milestone Oct 20, 2021
@MihaZupan MihaZupan merged commit d4bf856 into microsoft:main Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pool CancellationTokenSources in 6.0+
4 participants